import path from 'path'
import type { NuxtConfig } from '@nuxt/types'
import { isDev } from './utils/env'

const config: NuxtConfig = {
  // Global page headers: https://go.nuxtjs.dev/config-head
  env: {
    NODE_ENV: process.env.NODE_ENV || 'http://47.108.234.167:30080/api/tenant/',
    BASE_URL: process.env.BASE_URL || 'http://47.108.234.167:30080/api/tenant/',
  },
  head: {
    title: '园查查',
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    'ant-design-vue/dist/antd.less',
    '@/assets/font/iconfont.css',
    'mapbox-gl/dist/mapbox-gl.css',
    'swiper/css/swiper.css',
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '@/plugins/antd-ui',
    '@/plugins/element-ui',
    '@/plugins/injectStore.ts',
    '@/plugins/swiper.js',
    '@/plugins/config.ts',
    { src: '@/plugins/client.ts', mode: 'client' },
    { src: '@/plugins/amapLoader.js', mode: 'client' },
    // { src: '@/plugins/importEchart.js', mode: 'client' },
    // { src: '@/plugins/swiper.js', mode: 'client' },
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // beta 版本，一引用就报错
    // '@nuxtjs/composition-api/module',
    // https://go.nuxtjs.dev/typescript
    [
      '@nuxt/typescript-build',
      {
        // 临时解除打包时取消类型判断
        typeCheck: false, // !isProd,
      },
    ],
    // https://go.nuxtjs.dev/stylelint
    // '@nuxtjs/stylelint-module',

    '@nuxtjs/tailwindcss',

    '@nuxtjs/router',

    '@nuxtjs/svg',
  ],
  routerModule: {
    keepDefaultRouter: true,
    path: path.resolve(__dirname, 'router'),
    fileName: 'index.ts',
  },
  router: {
    middleware: [], // ['auth'],
  },
  // Modules: https://go.nuxtjs.dev/config-modules
  modules: ['@nuxtjs/axios', '@nuxtjs/auth-next'],
  server: {
    host: '0.0.0.0',
  },
  tailwindcss: {
    cssPath: '~/assets/scss/tailwind.scss',
    exposeConfig: false,
    // config: {},
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    loaders: {
      scss: {
        // @ts-ignore
        additionalData: '@import "@/uni.scss";',
      },
      less: {
        // @ts-ignore
        lessOptions: {
          modifyVars: {
            hack: `true; @import "@/uni.less";`,
          },
          javascriptEnabled: true,
        },
      },
    },
  },
}

if (isDev) {
  config.modules?.push([
    // 这个以后决定线上的跨域模式，先在开发环境做正向代理
    '@nuxtjs/proxy',
    {
      pathRewrite: { '^/api': 'http://47.108.161.74:30080/api/tenant/' },
    },
  ])
}
export default config
